﻿using ClassLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class Edit : System.Web.UI.Page
    {

        connectionClass conn = new connectionClass();
        System.Data.DataSet dataS = new System.Data.DataSet();
        System.Data.DataTable dataT = new System.Data.DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            tableNames();
        }

        protected void tableNames()
        {
            try
            {
                conn.getConnection();
                try
                {
                    dataS = conn.getTableNames();
                    dataT = dataS.Tables[0];
                   // Response.Write("<Body> <p>");
                    foreach (System.Data.DataRow dataR in dataT.Rows)
                    {

                        if (!dataR[0].ToString().Substring(0, 3).Equals("asp"))
                        {
                            if (!dataR[0].ToString().Equals("campingsperfestival"))
                            {
                                String hulp = dataR[0].ToString().Substring(0, 1).ToUpper() + dataR[0].ToString().Substring(1);
                               // Response.Write("<a href=/EditPages/" + hulp + ".aspx>" + hulp + "</a><br />");   
                                Button btn = new Button();
                                btn.ID = hulp;
                                btn.Text = hulp;
                                btn.Click += btn_Click; // wire up the event
                                btn.Visible = true;
                                buttonsholder.Controls.Add(btn);
                                buttonsholder.Visible = true;
                            }
                                        
                        }
                        conn.closeConnection();
                    }

                   // Response.Write("</p> </body>");
                }
                catch (Exception ex)
                {
                    Logs.Log(ex.Message + " " + ex.StackTrace);
                    Response.Redirect("/Oops.aspx");
                }
            }
            catch (Exception ex)
            {
                Logs.Log(ex.Message + " " + ex.StackTrace);
                Response.Redirect("/Oops.aspx");
            }
        }

        private void btn_Click(object sender, EventArgs e)
        {
            Button a = sender as Button;
            Response.Redirect("~/EditPages/" + a.Text.ToString() + ".aspx");
        }
    }
}